package cn.com.self.apis.member.controller;


import cn.com.self.apis.core.vo.ResultModel;
import cn.com.self.apis.member.entity.UTalentRecommendation;
import cn.com.self.apis.member.service.ITalentRecommendationService;
import cn.com.self.apis.portal.util.ICustomPage;
import cn.com.self.apis.util.CopyUtils;
import cn.com.selfsoft.smartcity.commons.http.DataItem;
import cn.com.selfsoft.smartcity.commons.http.DataPage;
import cn.com.selfsoft.smartcity.commons.util.ParameterUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.Map;

/**
 * @author L
 * @title: AdvertisementController
 * @projectName self
 * @description: TODO
 * @date 2021/1/11 17:16
 */
@Controller
@RequestMapping("/talentRecommendation")
@Api(tags = "人才推荐信息类")
public class TalentRecommendationController {
    @Autowired
    private ITalentRecommendationService talentRecommendationService;
    /**新增推荐
     * @Description //TODO
     * @return
     **/
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增推荐信息")
    public ResponseEntity create(@RequestBody @Valid UTalentRecommendation entity, HttpServletRequest request){
        entity.setCreateTime(new Date());
        UTalentRecommendation create = talentRecommendationService.create(entity);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(create));
    }


    /**分页获取推荐列表
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "分页获取推荐列表")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "memberId", value = "会员id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "size", value = "一页显示条数", required = false, dataType = "String")
    })
    public ResponseEntity getEscrowInfoPage(HttpServletRequest request, Pageable page){
        Map<String, Object> queryParams = ParameterUtil.HumpToUnderline(request.getParameterMap(), "mark", "size", "page","sort","access_token");
        ICustomPage<UTalentRecommendation> pageData = this.talentRecommendationService.page(queryParams, page);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(pageData));

    }

    /**获取推荐信息
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "获取推荐信息")
    @RequestMapping(value = {"/load/{id}"}, method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity loadEscrowInfo(@PathVariable("id") String id, HttpServletRequest request) {
        UTalentRecommendation talentRecommendation = this.talentRecommendationService.load(id);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(new DataItem(talentRecommendation)));

    }


    /**修改推荐信息
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "修改推荐信息")
    @RequestMapping(value = {"/update/{id}"}, method = RequestMethod.POST)
    @ResponseBody
    public ResponseEntity update(@PathVariable("id") String id, @RequestBody UTalentRecommendation entity, HttpServletRequest request) {
        UTalentRecommendation talentRecommendation = this.talentRecommendationService.load(id);
        CopyUtils.copyProperties(entity, talentRecommendation);
        talentRecommendation.setUpdateTime(new Date());
        UTalentRecommendation update = this.talentRecommendationService.update(talentRecommendation);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(new DataItem(update)));

    }


    /**删除推荐信息
     * @Description //TODO
     * @return
     **/
    @ApiOperation(value = "删除推荐信息")
    @ResponseBody
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public ResponseEntity deletes(@PathVariable("id") String id){
        this.talentRecommendationService.delete(id);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(1));
    }
}
